module.exports = function ($scope, $state, $stateParams,$resource,$modal, toaster, car_code) {  
    console.log(car_code);
    $scope.employee='';
    $scope.ctarr=[
        {name:'普通货车',value:'0'},
        {name:'厢式专用运输车',value:'1'},
        {name:'罐式专用运输车',value:'2'},
    ]
    $scope.info = {
        'list' : [],
        'photo' : ''
    }
    $scope.vm = {
        'date' : '',
        'options' : {
            format: "YYYY-MM-DD",
            locale : 'zh-cn'
        }
    }
    $scope.vm1 = {
        'date' : '',
        'options' : {
            format: "YYYY-MM-DD",
            locale : 'zh-cn'
        }
    }
    $scope.vm2 = {
        'date' : '',
        'options' : {
            format: "YYYY-MM-DD",
            locale : 'zh-cn'
        }
    }
    $scope.vm3 = {
        'date' : '',
        'options' : {
            format: "YYYY-MM-DD",
            locale : 'zh-cn'
        }
    }

    if(car_code){
        $resource('/api/as/dsc/traffic/getCarInfoList ', {}, {}).save({'car_code' : car_code}, function(res){
            console.log($scope.info);
            if(res.errcode !== 0){            
                toaster.error({title:"",body:res.errmsg});
            }else{
                console.log('详情');
                console.log(res);
                $scope.info = res.data[0];

            }
        });

    }

    // 驾驶员列表
    $resource('/api/as/dsc/traffic/findDriverList', {}, {}).save({}, function(res){
        console.log($scope.info);
        if(res.errcode !== 0){            
            toaster.error({title:"",body:res.errmsg});

        }else{
            console.log('驾驶员列表');
            $scope.driverarr = res.data;
            console.log(res);
        }
    });

    $scope.change = function(info){
        console.log(info);
    }

    $scope.image = function(){
        var para = $state.get('app.imageupload');
        //设置上传文件夹，以自己业务命名
        angular.extend(para, {
            resolve : {  
                'dir' : function(){
                    return 't1';
                }
            } 
        })
        console.log(para);
        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  
            console.log(result);  
            $scope.imagearr = JSON.stringify(result);
            $scope.info.photo = result.join(",");
            $scope.array = result;

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    };

    $scope.del=function(index){
        $scope.array.splice(index,1);
        $scope.info.photo=$scope.array;
    }


    $scope.save = function(){
        $scope.info.business_license_validity = $scope.vm.date;
        console.log($scope.info);
        $resource('/api/ac/dsc/trafficService/create', {}, {}).save($scope.info, function(res){
            if(res.errcode !== 0){  
                toaster.error({title:"",body:res.errmsg});
            }else{
                toaster.success({title:"",body:"操作成功"});
                $modalInstance.close();
            }
        });
    }

            //正则判断电话号  
            $scope.checkphone=function(x){
                if(!/^1[34578]\d{9}$/.test(x)) return "您输入的电话号长度或格式错误";
            }
			$scope.showphoneinfo=function(x){
                console.log(x);
                if(x==undefined){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                if(x==''){
                    $scope.employee.phoneinfo="";
                   return;
                  }
                                         
            if($scope.checkphone(x)=="您输入的电话号长度或格式错误"){                
                $scope.employee.phoneinfo="您输入的电话号长度或格式错误"
            }else{
                     $scope.employee.phoneinfo="";
                    }
            }


};
